package com.agy.filemanager.controller;

import com.agy.filemanager.common.TreeUtil;
import com.agy.filemanager.entity.DcDocProjectStepType;
import com.agy.filemanager.entity.TreeModel;
import com.agy.filemanager.service.DcDocProjectStepTypeService;
import com.agy.filemanager.toolClass.Result;
import com.agy.filemanager.toolClass.ResultUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Zhang Fan
 * @date 2018\8\14 0014 14:09
 * @desc 项目阶段类型Controller层
 */
@Controller
@RequestMapping("/projectsteptype")
public class DcDocProjectStepTypeController {

    @Autowired
    DcDocProjectStepTypeService dcDocProjectStepTypeService;

    @RequestMapping("/getDcDocProjectStepType")
    @ResponseBody
    public Result getDcDocProjectStepType(){
        List<DcDocProjectStepType> list = dcDocProjectStepTypeService.getDcDocProjectStepType();
        return ResultUtil.success(list, "成功");
    }

    /**
     * 获取项目分类组织机构树
     * @return
     */
    @RequestMapping ("/selectTree")
    @ResponseBody
    public Result selectTree(){
        List<TreeModel> list =null;
        try{
            list = TreeUtil.getTree(dcDocProjectStepTypeService.selectTree());
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return ResultUtil.success(list, "成功");
    }

    @RequestMapping ("/selectTable")
    @ResponseBody
    public Map<String,Object> selectTable(HttpServletRequest request){
        int pageNum = Integer.parseInt(request.getParameter("pageNum"));
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        Page list = null;
        try{
            list = dcDocProjectStepTypeService.selectTable(pageNum,pageSize);
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        Map<String,Object> map = new HashMap();
        map.put("total",list.getTotal());
        map.put("rows",list.getResult());
        return map;
    }

}
